<?php

class Employee_EstateController extends Zend_Controller_Action{
	
	public function indexAction(){
		
	}

    public function registerAction(){
        $this->_helper->viewRenderer->setNoRender(TRUE);
        $this->_helper->layout()->disableLayout();
        $request = $this->getRequest();
        $params = array_diff($request->getParams(), $request->getUserParams());
        $estate = array();
        foreach ($params as $colName => $value) {
            if (is_array($value)) {
                foreach ($value as $key => $arrayVal) {
                    $value[$key] = htmlentities(trim($arrayVal));
                }
            }else {
                $value = htmlentities(trim($value));
            }
            $estate[$colName] = $value;
        }
        if ('sqft' != $estate['area_unit']) {
            $estate['total_area'] = $this->_helper->UnitConverter($estate['total_area'],$estate['area_unit']);
        }
        $project = new Reale_Model_Estate_Project($estate);
        
        $oper = $request->getParam('oper');
        switch ($oper) {
            case 'add':
            case 'mod':
                if ($project->save()) {
                    echo 'Submitted successfully with registration number: '.$project->getEstate_Type().'-'.$project->getEstate_id();
                    return;
                }
                
            break;
            case 'del':
            break;
            default:
                throw new Zend_Exception('"'.$oper.'" is unknown operation.', Zend_Log::ERR);
            break;
        }
        throw new Zend_Exception('Operation on project not successfull.', Zend_Log::ERR);
    }
    
	public function editAction()
	{
		
	}
}